<%@ page language="java" import="java.util.*"  contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.Utils.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String path = request.getContextPath();

%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>所有文件</title>
<script type="text/javascript">
function getSelectCount(){
	var names = document.getElementsByName("chbox");
	var count = 0;
	for (var i = 0; i<names.length; i++){
		names[i].checked==true ? count++ : 0;
	}
	return count;
}
function del(){
	if(getSelectCount()==0){
		alert("至少选择一个删除项！");
		return;
	}
	var th = document.form1;
	var pageNum = document.getElementById("currentPage").value;
	th.action = "<%=path%>/DeleteFilesServlet?pageNum="+pageNum;
	th.submit();
}
function goPage(pageNum){
	location.href="<%=path%>/ShowFilesServlet?pageNum="+pageNum;
}
function changePage(){
	var pageNum = document.getElementById("currentPage").value;
	window.location.href="<%=path%>/ShowFilesServlet?pageNum="+pageNum;
}
function downloadZip(){
	if(getSelectCount()==0){
		alert("至少选择一个下载项！");
		return;
	}
	var th = document.form1;
	th.action = "<%=path%>/DownloadZipFilesServlet";
	th.submit();
}

</script>
</head>
<body>
	
	<form name="form1" action="" method="post">
		查询结果：
		<table border="2">
			<tr>
				<td width=10%></td>
				<td>文件名</td>
				<td>文件类别</td>
				<td>文件大小</td>
				<td>文件上传日期</td>
				<td width=10%></td>
			</tr>
			<c:forEach var="file" items="${pageBean.list}">
			    <c:url value="DownloadServlet" var="downurl">
							<c:param name="filename" value="${file.getFileName()}"></c:param>
			    </c:url>
				<tr>
					<td><input type="checkbox" name="chbox" value="${file.getFileName()}"></td>
					<td>${file.getFileName()}</td>
					<td>${file.getFileType()}</td>
					<td>${file.getFileSize()}</td>
					<td>${file.getFileDate()}</td>
					<td><a href="${downurl}">下载</a></td>
				</tr>
			</c:forEach>
		</table>
		<button type="button" onclick="downloadZip()">打包下载</button>&nbsp;&nbsp;
		<button type="button" onclick="del()">删除</button></br>
	共 ${pageBean.pageCount}页&nbsp;
	${pageBean.totalCount}条记录&nbsp;
	<a href="#" onclick="goPage(1)">首页</a>&nbsp;&nbsp;
	<a href="#" onclick="goPage(${pageBean.pageNum-1})">上一页</a>&nbsp;&nbsp;
	<a href="#" onclick="goPage(${pageBean.pageNum+1})">下一页</a>&nbsp;&nbsp;
	<a href="#" onclick="goPage(${pageBean.pageCount})">尾页</a>&nbsp;&nbsp;
	跳转到：<input style="width:30px; type="text" id="currentPage" value=${pageBean.pageNum}>
	<button type="button" onclick="changePage()">Go</button>
	</form>
	<button type="button" onclick="javascript:location.href='queryTerms.jsp'">重新查询</button>
</body>
</html>